package com.city.repository.report;

import com.city.domain.report.CtDoBan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface CtDoBanRepository extends JpaRepository<CtDoBan,Integer> {
    @Query(value =  "SELECT * FROM ct_do_ban " +
                    "WHERE report_id = ?1 limit 1",nativeQuery = true)
    CtDoBan findByReportId(Integer reportId);

    @Transactional
    @Modifying
    @Query(value =  "DELETE FROM ct_do_ban " +
                    "WHERE report_id = ?1 " +
                    "AND man_id = ?2",nativeQuery = true)
    void deleteByReportIdAndManId(Integer reportId, Integer manId);

    @Query(value =  "SELECT * FROM ct_do_ban " +
                    "WHERE report_id = ?1 " +
                    "AND man_id = ?2 " +
                    "limit 1",nativeQuery = true)
    List<CtDoBan> findByReportIdAndManId(Integer reportId, Integer manId);

    @Query( value = "SELECT * FROM ct_do_ban " +
                    "WHERE report_id = ?1 ",nativeQuery = true)
    List<CtDoBan> findAllByReportId(Integer reportId);

    @Query( value = "SELECT * FROM ct_do_ban " +
                    "WHERE report_id = ?1 " +
                    "ORDER BY create_time desc ",nativeQuery = true)
    List<CtDoBan> findAllByReportIdOrderByTimeDesc(Integer reportId);

    @Query( value = "SELECT * FROM  ct_do_ban " +
                    "WHERE light = 0 ",nativeQuery = true)
    List<CtDoBan> findAllByLightEqZero();
}
